Skip to content

Don't evaluate positional after_scale aesthetics when building a legend - #1072

Merged
has2k1 merged 2 commits into
mainfrom
guide-assignment
Jun 11, 2026
Merged

Don't evaluate positional after_scale aesthetics when building a legend#1072
has2k1 merged 2 commits into
mainfrom
guide-assignment

Conversation

@has2k1

@has2k1 has2k1 commented Jun 11, 2026

Copy link
Copy Markdown
Owner

No description provided.

has2k1 added 2 commits June 10, 2026 21:43
Make scale_discrete generic over GuideTypeT instead of hardcoding
guide: Literal["legend"] | None, and add OptionalLegend,
OptionalColorbar and OptionalGuide aliases to _runtime_typing.
Each discrete scale subclass now declares its own guide field.

Behavior change: identity scales for color, fill, shape, linetype
and alpha now default to guide="legend" (size and stroke keep None).
scale_position_discrete declares guide: None as a field instead of
assigning it in __post_init__.
Legend key data can only contain the matched legend aesthetics and the
geom's default aesthetics. Staged positional aesthetics (e.g. x, y)
never appear in it, so evaluating their after_scale expressions against
the key data raised a PlotnineError, triggered a spurious "this should
not happen" warning, and discarded all legitimate legend modifiers via
the fallback path. Filter the modifiers to aesthetics that can be in
the key data before evaluation.

closes #1067
@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.14%. Comparing base (e846b3a) to head (82f2d3f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1072      +/-   ##
==========================================
+ Coverage   87.10%   87.14%   +0.04%     
==========================================
  Files         208      208              
  Lines       14321    14338      +17     
  Branches     1788     1788              
==========================================
+ Hits        12474    12495      +21     
+ Misses       1283     1280       -3     
+ Partials      564      563       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@has2k1
has2k1 merged commit 82f2d3f into main Jun 11, 2026
14 checks passed
@has2k1
has2k1 deleted the guide-assignment branch June 11, 2026 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant